<template>
	<view>
		<view style="height: 1rpx; width: 1rpx"></view>
		<view class="address-each" v-for="(item, index) in list" @click="select(item)">
			<view class="image"><image :src="cheType.indexOf(item.id) != -1 ? '../../static/choosed.png' : '../../static/choose.png'" mode=""></image></view>
			<view class="yhq-each">
				<view class="money">
					￥<text>{{item.money}}</text>
				</view>
				<view class="hint-r">
					<view class="Full-minus">满 <text>{{item.threshold}}</text> 元可减 <text>{{item.money}}</text> 元</view>
					<view class="time">有效天数：{{item.days}}天</view>
				</view>
			</view>
		</view>
		
		<view class="bottom-btn">
			<view class="quanxuan">
				<image @click="quanxuan" :src="SelectAll ? '../../static/choosed.png' : '../../static/choose.png'" mode=""></image>
				{{SelectAll ? '全不选' : '全选'}}
				
				<text>共计：</text>
				{{cheType.length}}张
			</view>
			<view class="btn" @click="confirmYhq">确定</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list:[],
			id:'',
			cheType:[]
		};
	},
	onLoad(option) {
		this.id = option.id
		this.getCoupon()
	},
	computed:{
		SelectAll(){
			if(this.cheType.length == this.list.length){
				return true
			}else {
				return false
			}
		}
	},
	methods: {
		getCoupon(){
			this.$api.post('/getMyCoupon',{type:3}).then(res => {
				this.list = res.data
			}).catch(res => {
				
			})
		},
		//全选
		quanxuan(){
			if(this.SelectAll){
				this.cheType = []
			}else {
				this.cheType = []
				this.list.map(item => {
					this.cheType.push(item.id)
				})
			}
		},
		select(item){
			if (this.cheType.indexOf(item.id) == -1) {
				this.cheType.push(item.id)
			} else {
				this.cheType.splice(this.cheType.indexOf(item.id), 1);
			}
		},
		confirmYhq(){
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.emit('selectYhq',this.cheType);
			this.$back();
		}
	}
};
</script>

<style lang="scss">
	page {
		background-color: #F6F8FA;
	}
.address-each {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 32rpx;
	margin-top: 24rpx;
	.image {
		width: 32rpx;
		height: 32rpx;
		padding-right: 24rpx;
		image {
			width: 32rpx;
			height: 32rpx;
		}
	}

	.yhq-each {
		padding: 32rpx;
		width: 622rpx;
		background: #FFFFFF;
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		margin: auto;
		display: flex;
		align-items: center;
		margin-top: 24rpx;
		color: #A4A9B7;
		.money {
			font-weight: bold;
			font-size: 30rpx;
			color: #4BC264;
			text {
				font-size: 56rpx;
			}
			margin-right: 32rpx;
		}
		.hint-r {
			.Full-minus {
				font-weight: bold;
				font-size: 30rpx;
				color: #1C274C;
				text {
					color: #4BC264;
				}
			}
			.time {
				font-weight: 500;
				font-size: 22rpx;
				color: #A4A9B7;
				margin-top: 16rpx;
			}
		}
	}
}

.bottom-btn {
	width: 686rpx;
	padding: 0 32rpx 32rpx 32rpx;
	height: 126rpx;
	background: #FFFFFF;
	border-radius: 0rpx 0rpx 0rpx 0rpx;
	position: fixed;
	bottom: 0;
	
	display: flex;
	justify-content: space-between;
	align-items: center;
	.quanxuan {
		font-weight: 500;
		font-size: 24rpx;
		color: #1C274C;
		image {
			width: 32rpx;
			height: 32rpx;
			vertical-align: middle;
			padding-right: 8rpx;
		}
		text {
			font-weight: 500;
			font-size: 24rpx;
			color: #A4A9B7;
			padding: 0 0 0 24rpx;
		}
	}
	.btn {
		width: 354rpx;
		height: 90rpx;
		background: #4BC264;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		font-weight: bold;
		font-size: 30rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 90rpx;
	}
}
</style>
